package dj.MyNote;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.TextView;

public class MyNoteShow extends Activity {
	
	DataBaseHelper dbHelper = null;
	SQLiteDatabase db = null;
	int selectedPos = 0;
	private List<HashMap<String, Object>> mData;
	
	TextView textViewTitle = null;
	TextView textViewContent = null;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.show);
        
        dbHelper = new DataBaseHelper(MyNoteShow.this,"dj_note_db");
		db = dbHelper.getReadableDatabase();
		selectedPos = this.getIntent().getIntExtra("SelectedItemPos", 0);
		
		mData = new ArrayList<HashMap<String, Object>>();
		Cursor cursor = db.query("MyNoteData", new String[]{"id","title","content","modifytime"}, "id="+selectedPos, null, null, null, "modifytime desc");
		           
        while(cursor.moveToNext())
        {
        	cursor.moveToFirst();
        	int	id = cursor.getInt(cursor.getColumnIndex("id"));
        	String title = cursor.getString(cursor.getColumnIndex("title"));
        	String content = cursor.getString(cursor.getColumnIndex("content"));
        	
        	HashMap< String, Object> map = new HashMap< String, Object>();
        	map.put("Id",id);
        	map.put("ItemTitle", title);
        	map.put("ItemContent", content);
        	mData.add(map);
        }
        
        textViewTitle = (TextView)findViewById(R.id.show_title);
        textViewContent = (TextView)findViewById(R.id.show_content);
        
        
        textViewTitle.setText((String)mData.get(0).get("ItemTitle"));
        textViewContent.setText((String)mData.get(0).get("ItemContent"));
        
    }

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		
		if(keyCode == KeyEvent.KEYCODE_BACK){
			Intent intent = new Intent();
			intent.setClass(MyNoteShow.this, MyNoteListShow.class);
			MyNoteShow.this.startActivity(intent);
			MyNoteShow.this.finish();
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}
    
}